package jianzhiOffer;

public class test06 {
    public static int[] twoSum(int[] numbers, int target) {

        int target_half  =target/2;
        int high = numbers.length-1;
        int low = 0;
        int half;
        while ((high-low)!=1&&(high-low)!=0){
            half = (low+high)/2;
            if(numbers[half]<target_half){
                low = half;
            }else if(numbers[half]>target_half){
                high = half;
            }else{
                low=half;
                high=half;
            }
        }
        if (low-1>=0&&(numbers[low-1]+numbers[high])==target){
            return new int[]{low-1,high};
        }
        if (high+1<numbers.length&&(numbers[low]+numbers[high+1])==target){
            return new int[]{low,high+1};
        }
        while(!(((numbers[low]+numbers[high])==target)&&(low!=high))){
            if((numbers[low]+numbers[high])>target){
                low-=1;
            }else if((numbers[low]+numbers[high])<target){
                high+=1;
            }else{
                low-=1;
                high+=1;
            }
        }
        return new int[]{low,high};
    }

    public static void main(String[] args) {
        int[] a=new int[]{0,0,3,4};
        System.out.println(twoSum(a,0)[0]);
        System.out.println(twoSum(a,0)[1]);
    }
}
